home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 119 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.7 KB  |  86 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: David Byrden <100101.2547@compuserve.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Give operator. a chance
  5. Date: 22 Jan 1996 19:50:27 GMT
  6. Organization: self-employed
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4e0pj1$rq6@news.bridge.net>
  9. References: <3102AD11.1663@et.se>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset="us-ascii"
  13. Content-Transfer-Encoding: 7bit
  14. X-Nntp-Posting-Host: ppp-mia1-45.bridge.net
  15. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  16. X-Lines: 61
  17. Content-Length: 1888
  18. Originator: clamage@taumet
  19.  
  20.  
  21. Dan;
  22.  
  23.  
  24. >>  Is operator.() banned from the standards discussion?
  25.  
  26. No, but the time for public contributions to the standards discussion 
  27. ended over 6 months ago.
  28.  
  29.  
  30. >> Ideally, operator.() should allow you to have all the things
  31. >> inheritance allows you to have, except for storage. I.e. a class
  32. >> with operator.() should behave just as its "base class", but be
  33. >> allowed to override suitable functions.
  34. >> Why isn't this possible? What's the catch?
  35.  
  36. New facilities are not added to the C++ language when their effect can be 
  37. attained by a little programming using existing facilities.
  38.  
  39. From your description, it seems to me that an your operator.() object 
  40. method would return a reference to another object, and the named member 
  41. function would be called in that object. For example, here is class 
  42. Handle acting as a proxy for a class Bitmap;
  43.  
  44.  
  45.    Handle h ;          // class Handle overloads operator.()
  46.    h.display() ;       // h returns a reference to a Bitmap object
  47.                        // whose display() is then called
  48.  
  49.  
  50. Operator.() was not overloaded because you can achieve exactly this same 
  51. effect without it, if the clas Handle has a set of member functions 
  52. matching those in Bitmap, The Handle member functions can simply make 
  53. inline calls to the Bitmap member functions; they can also override to 
  54. change behaviour where necessary:
  55.  
  56.  
  57. class Handle {
  58.    Bitmap & ref ;
  59. public:
  60.    bool display()
  61.    {
  62.         return  ref.display() ;
  63.    }
  64. } ;
  65.  
  66.  
  67. Various implementations of this kind of scheme are described in the 
  68. literature, for example Coplein, My favourite implementation is where the 
  69. handle class, and the genuine class, both inherit their interface from 
  70. the same abstract base class.
  71.  
  72.  
  73.                                        David Byrden
  74.  
  75.  
  76.  
  77.            || C++ training for professional programmers ||
  78.            ||   My opinions ARE those of my employer.   ||
  79.  
  80.  
  81.  
  82. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  83.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  84.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  85.  
  86.